package com.example.houduan.Controller;

import com.example.houduan.Pojo.MedicalPolicy;
import com.example.houduan.Service.MedicalPolicyService;
import com.example.houduan.Utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Controller
@CrossOrigin
public class MedicalPolicyController {
    @Autowired
    MedicalPolicyService medicalPolicyService;

    @RequestMapping("/getMedicalPolicyPage")
    @ResponseBody
    public PageModel getMedicalPolicyPage(@RequestParam int num,int size){
        return medicalPolicyService.getMedicalPolicyPage(num, size);
    }

    @RequestMapping("/deleteMedicalPolicy")
    @ResponseBody
    public String deleteMedicalPolicy(@RequestParam Integer medicalpolicy_id){
        if (medicalPolicyService.deleteMedicalPolicy(medicalpolicy_id)==0){
            return "删除失败";
        }else{
            return "删除成功";
        }
    }

    @RequestMapping("/updateMedicalPolicy")
    @ResponseBody
    public String updateMedicalPolicy(@RequestBody MedicalPolicy medicalPolicy){
        medicalPolicy.setUpdatetime(LocalDateTime.now());
        if(medicalPolicyService.updateMedicalPolicy(medicalPolicy)==0){
            return "更新失败";
        }else{
            return "更新成功";
        }
    }

    @RequestMapping("/addMedicalPolicy")
    @ResponseBody
    public String addMedicalPolicy(@RequestBody MedicalPolicy medicalPolicy){
        medicalPolicy.setUpdatetime(LocalDateTime.now());
        medicalPolicy.setCreatetime(LocalDateTime.now());
        if(medicalPolicyService.addMedicalPolicy(medicalPolicy)==0){
            return "添加失败";
        }else {
            return "添加成功";
        }
    }

    @RequestMapping("/getAllMedicalPolicy")
    @ResponseBody
    public List<MedicalPolicy> getAllMedicalPolicy(){
        return medicalPolicyService.getAllMedicalPolicy();
    }

}
